import 'package:mfkb/config/Config.dart';
import 'package:mfkb/util/HttpUtil.dart';

class MarketService {
  Future<dynamic> init() async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/init") ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> types(int id) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/types?id="+id.toString()) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> goods(int id) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/goods?id="+id.toString()) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> goodsDetail(int id) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/goodsdetail?id="+id.toString()) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> addGoodsToCart(int id , int sid) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/addGoodsToCart?gid="+id.toString()+"&sid="+sid.toString()) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> cartGoods() async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/cartGoods") ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> cartData() async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/cartData") ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> deleteGoodsInCart(int cid) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/deleteGoodsInCart?id="+cid.toString()) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> addPlace(String pname , String pphone , String pplace , String detail) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/addPlace?pname="+pname+"&pphone="+pphone+"&pplace="+pplace+"&detail="+detail) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> getDefPlace() async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/getDefPlace") ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> createOrder(String param) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/createOrder?param="+param) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> payInfo(String orderId) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/payinfo?orderId="+orderId) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> canclePay(String orderId) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/canclePay?orderId="+orderId) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }

  Future<dynamic> payCheck(String orderId) async{
    dynamic data ;
    try {
      data = await HttpUtil().get(Config().getHost()+"/api/admin/v1/payCheck?orderId="+orderId) ;
    } catch (e) {
      data = {"code":500 , "msg":"网络错误" , "data":""} ;
    }
    return data ;
  }
}